%Image Processing Assignment - 7
%Name: - Kirtish Dhande
%Class: - B.E. - C
%Roll no: - 54
% This is the program for Color SVD
%Date of assignment - 15/03/2016
clc;
close all;

clear all;

A = double(imread('sunset.bmp'));
%figure,imshow(imread('sunset.bmp'));
[m,n] = size(A(:,:,1));
RGB = zeros(size(A));
[ur sr vr] = svd(A(:,:,1));
[ug sg vg] = svd(A(:,:,2));
[ub sb vb] = svd(A(:,:,3));
k = input('Enter the number of components');
for i = 1:k
   RGB(:,:,1) = RGB(:,:,1) +(sr(i,i)*ur(:,i)*vr(:,i).');
   RGB(:,:,2) = RGB(:,:,2) +(sg(i,i)*ug(:,i)*vg(:,i).');
   RGB(:,:,3) = RGB(:,:,3) +(sb(i,i)*ub(:,i)*vb(:,i).');
end
cr = m*n/(k*(m+n+1));
disp(cr);
%figure,imshow(uint8(RGB));
title('Color SVD');
imshowpair(uint8(A),uint8(RGB),'montage');